package Work.stringWork2;

import java.util.Scanner;

/*
* 2、输入一个字符串，输入一个要查找的字符串，判断查找的字符串在字符串中出现的次数

    要求：查找的字符串随便输入，都可以查询出总数。
* */
public class FindString {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int count = 0;
        System.out.println("请输入一句话：");
        String sentence = input.next();
        String[] array = new String[sentence.length()];
        System.out.println("请输入你要查找的字符：");
        String find = input.next();
        array = sentence.split(find);
        for (int i = 0; i < array.length; i++) {
            System.out.println(find + (i + 1) + "次");
            count++;
        }
        System.out.println(find + "在句子中出现的次数为：" + count + "次。");
    }
}
